<template>
  <div>
    <div class="title">
      <div :class="now? 'title-index':'title-index-y'" @click="now = 0" style="border-top-left-radius: 6px;border-bottom-left-radius: 6px">问题信息</div>
      <div :class="!now? 'title-index':'title-index-y'" @click="now = 1" style="border-top-right-radius: 6px;border-bottom-right-radius: 6px">打卡详情</div>
    </div>
    <a-spin :spinning="confirmLoading">
      <div v-if="!now">
        <div class="item-box">
          <span class="item-title">学生姓名</span>
          <span class="item-value">{{ alarmInfo.studentName }}</span>
        </div>
        <div class="item-box">
          <span class="item-title">学生学号</span>
          <span class="item-value">{{ alarmInfo.studentCode }}</span>
        </div>
        <div class="item-box">
          <span class="item-title">学生班级</span>
          <span class="item-value">{{ alarmInfo.major }}</span>
        </div>
        <div class="item-box">
          <span class="item-title">学生电话</span>
          <span class="item-value">{{ alarmInfo.mobile }}</span>
        </div>
        <div class="item-box">
          <span class="item-title">问题时段</span>
          <span class="item-value">{{ alarmInfo.timeScope }}</span>
        </div>
        <div class="item-box">
          <span class="item-title">异常类型</span>
          <span class="item-value">{{ alarmInfo.alarmType }}</span>
        </div>
        <div class="item-box">
          <span class="item-title">规定方向</span>
          <span class="item-value">{{ alarmInfo.direction }}</span>
        </div>
        <div class="item-box">
          <span class="item-title">处理状态</span>
          <span class="item-value">{{ alarmInfo.status }}</span>
        </div>
        <div class="item-box" v-if="processed">
          <span class="item-title">情况说明</span>
          <span class="item-value">{{ alarmInfo.description }}</span>
        </div>
        <div class="item-box" v-if="!processed">
          <span class="item-title" style="height: 32px;line-height: 32px">异常情况说明</span>
          <span class="item-value" style="height: 32px;line-height: 32px">
            <a-select
              :allowClear="true"
              placeholder="请选择"
              v-model="queryParam.description"
              @change="changeDescription"
              :options="descriptionList"
              style="width: 200px"
            >
            </a-select>
          </span>
        </div>
        <a-button v-if="!processed" class="button" @click="submit">
          提交
        </a-button>
      </div>
      <div v-if="now">
        <div class="item-box" v-for="(item,i) in list" :key="i">
          <span class="item-title">{{item.checkTime}}</span>
          <span class="item-value">{{ item.deviceGroup }}</span>
        </div>
      </div>
    </a-spin>
  </div>
</template>

<script>
import {TableMixin} from '@/mixins/TableMixin'
import {getAlarmInfo, getInfoByStudentId, listDescription, processAlarm,} from "@api/wfuAlarm/wfuAlarm";
import {test} from "@api/base/apiTest";

export default {
  components: {},
  mixins: [TableMixin],
  name: 'processAlarmMobile',
  data() {
    return {
      visible: false,
      confirmLoading: false,
      columns: [
        {
          title: '打卡时间',
          field: 'checkTime',
        },
        {
          title: '打卡地点',
          field: 'deviceGroup',
        },
      ],
      alarmInfo: {
        studentId: '',
        studentName: '',
        studentCode: '',
        major: '',
        mobile: '',
        timeScope: '',
        alarmType: '',
        previousAddress: '',
        direction: '',
        status: '',
        description: ''
      },
      descriptionList: [],
      queryParam: {
        institute: '',
        assistantId: '',
        studentName: '',
        timeScope: '',
        alarmType: '',
        studentId: '',
        description: ''
      },
      now: 0,
      height: 300,
      processed: undefined,
      list: []
    }
  },
  created() {
    this.init()
  },
  methods: {
    test() {
      test()
    },
    init() {
      this.queryParam = this.$route.query
      this.confirmLoading = true
      listDescription().then(res => {
        this.confirmLoading = false
        this.descriptionList = res.data
      })
      getInfoByStudentId(
        Object.assign(this.queryParam)
      ).then(res => {
        this.confirmLoading = false
        this.list = res.data
      })
      this.getAlarmInfo()
    },
    getAlarmInfo() {
      getAlarmInfo(this.queryParam).then(res => {
        this.alarmInfo = res.data;
        this.processed = this.alarmInfo.status === '已处理'
      })
    },
    submit() {
      this.confirmLoading = true
      return processAlarm(this.queryParam).then(res => {
        this.confirmLoading = false
        this.getAlarmInfo()
      })
    },
    changeDescription(e) {
      this.queryParam.description = e
    }
  }
}
</script>

<style scoped>
  .button{
    margin: 15px;
    width: -webkit-fill-available;
  }
  .title{
    margin: 1px 15px;
    height: 30px;
    /*border-radius: 5px;*/
    /*width: 100%;*/
    /*background: #0c8fcf;*/
    line-height: 30px;
    text-align: center;
    /*color: #fff;*/
    /*border: 1px solid #0c8fcf;*/
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .title-index{
    flex: 1;
    border: 1px solid #0c8fcf;
    text-align: center;
    transition: all 0.3s;
  }
  .title-index-y{
    border: 1px solid #0c8fcf;
    flex: 1;
    background: #0c8fcf;
    color: #fff;
    text-align: center;
    transition: all 0.3s;
  }
  .item-box{
    padding: 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #eaebec;
  }
  .item-title{
    height: 24px;
    line-height: 24px;
  }
  .item-value{
    height: 24px;
    line-height: 24px;
  }

</style>
